#include "../utils/utils.hpp"
#include "analogy.hpp"
#include "entity.hpp"

namespace mashine { namespace kb {

using namespace std;

/**
 *
 */
Analogy::Analogy() : Entity<string>("", new vector<string *>())
{
	APP_LOGGER(info) << "Analogy {" << "empty" << "} instantiated";
}

/**
 *
 */
Analogy::Analogy(string name, string analog1, string analog2)
	: Entity<std::string>(name, new vector<string *>())
{
	params->push_back(&analog1);
	params->push_back(&analog2);

	APP_LOGGER(info) << "Analogy {" << toString() << "} instantiated";
}

/**
 *
 */
Analogy::~Analogy()
{
	APP_LOGGER(info) << "Analogy {" << toString() << "} begins to break down";
}

/**
 *
 */
Analogy::Analogy(Analogy const & analogy) : Entity<string>(analogy)
{
	APP_LOGGER(info) << "Analogy {" << analogy.toString() << "} copied";
}

/**
 * need owerride this method in child class 
 * to correct work Entity constructor
 */
bool Analogy::validateName(std::string & name) const
{
	APP_LOGGER(info) << "Analogy {" << toString() << "} name validating begin";
	
	return utils::is_analogy_name(name);
}

/**
 * need owerride this method in child class 
 * to correct work Entity constructor
 */
bool Analogy::validateParam(std::vector<std::string *> * params) const
{
	APP_LOGGER(info) << "Analogy {" << toString() << "} params validating begin";

	return params->size() == 2 && (
			(
			
				utils::is_constant_name(*(params->operator[](0))) && utils::is_constant_name(*(params->operator[](1)))
			
			) || (
			
				utils::is_variable_name(*(params->operator[](0))) && utils::is_variable_name(*(params->operator[](1)))
			
			));
}

string Analogy::toString() const
{
    string ret;

    ret += *name;
    ret += "(";

    vector<string *>::const_iterator i;
    for (i = params->begin(); i != params->end(); i++)
    {
        ret += **i;
        ret += ", ";
    }
	
	if (params->size() != 0) 
	{
		ret.erase(ret.size() - 2, 2);
    }
    ret += ")";

    return ret;
}

}}